package com.infore.airsupervise.ui.activity;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;


import com.beardedhen.androidbootstrap.font.FontAwesome;
import com.infore.airsupervise.R;
import com.infore.airsupervise.utils.ClickUtil;
import com.infore.airsupervise.utils.ToastUtil;
import com.tencent.bugly.beta.Beta;
import com.tencent.bugly.beta.upgrade.UpgradeStateListener;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AboutActivity extends BaseTitleBarActivity {

    @BindView(R.id.version_name)
    TextView versionName;
    @BindView(R.id.update_log)
    TextView updateLog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
        getWindow().setBackgroundDrawable(null);
        ButterKnife.bind(this);

        initView();
    }

    protected void initView() {
        title.setText("设置");
        rightMenu.setFontAwesomeIcon(FontAwesome.FA_QUESTION);

        // 展示版本信息
        showVersionInfo();
    }

    /**
     * 展示版本信息
     */
    private void showVersionInfo() {
        // 版本名
        try {
            PackageManager manager = this.getPackageManager();
            PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
            versionName.setText("V " + info.versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        // 更新日志
        updateLog.setText(R.string.version_info);
    }

    /**
     * 导航栏
     */
    @Override
    protected void onRightMenuClick(View view) {
        super.onRightMenuClick(view);
        ToastUtil.showShort(ctx,"帮助功能暂未开放，敬请期待...");
    }

    /**
     * 检测新版本
     */
    @OnClick(R.id.checkout_version)
    void checkoutVersion() {
        // 重复点击判断
        if (ClickUtil.isRepeatClick()) {
            return;
        }

        // 检查更新
        Beta.checkUpgrade();
    }
}
